var eventHandle = new Vue({
	el:"#event-handle-content",
	data: function() {
		return {
			showEquipInfo: true,
			showEquipmentDetail: false,
			//资产信息
			equipmentid: '',
			zcbh: '',
			tmbh: '',
			zybbh: '',
			type: '',
			name: '',
			vendor: '',
			model: '',
			depart:'',
			workshop: '',
			user: '',
			contact: '',
			location: '',
			note: '',
			recorder: '',
			putindate: '',
			state: '',
			//事件信息
			eventid: '',
			eventType: '',
			eventDesc: '',
			eventDepart: '',
			eventWorkshop: '',
			eventRecorder: '',
			eventRecordDate: '',
			eventAssistant: '',
			passOnDate: '',
			eventAssistant1: '',
			passOnDate1: '',
			//解决方案
			solutionError: '',
			solution: '',
			showPassOnBtn: false,
			submitTxt: '无法处理,向上提交'
		}
	},
	mounted: function () {
		var self = this;
		mui.init();
		mui.plusReady(function() {
			self.authControl();
			self.initValidator();
			self.initLayout();
			self.initData();
		})
	},
	methods:{
		authControl: function() {
			// 角色为部门IT人员或部门主管可以向上提交
			this.role = plus.storage.getItem('role');
			if(this.role == '1' || this.role == '2') {
				this.showPassOnBtn = true;
			}
		},
		initValidator: function() {
			this.constraints = {
				solution: {
					length: {
						maximum: 80,
						message: "长度不能超过80"
					}
				}
			};
		},
		passOnData: function() {
			/**
			 * 移交上级用户处理
			 */
			var self = this;
			var thisPage = plus.webview.currentWebview();
			var url = config.requestBaseUrl + "equipmentEventPassOn";
			mui.confirm('是否确认将该故障提交给上一级用户?','提示',['取消','确认'],function (e) {
				if(e.index == 1) {
					mui.ajax(url,{
						data:{
							eventid: self.eventid,
							role: self.role
						},
						dataType:'json',//服务器返回json格式数据
						type:'get',//HTTP请求类型
						timeout:5000,//超时时间设置为10秒；
						success:function(data){
							mui.toast(data.msg);
							if(data.isSuccess) {
								var indexPage = plus.webview.getLaunchWebview();
								mui.fire(indexPage,'refresh',{});
								thisPage.close();
							}
						},
						error:function(xhr,type,errorThrown){
							console.log(errorThrown)
							mui.toast("出错!请重试或联系管理员");
						}
					});
				}
			},'div')
		},
		initData: function () {
			var thisPage = plus.webview.currentWebview();
			
			if(thisPage.equipmentid) {
				this.showEquipInfo = true;
				this.equipmentid = thisPage.equipmentid;
				this.getEquipmentBaseData();
			} else {
				this.showEquipInfo = false;
			}
			/**
			 * 此页面的两个入口 1:首页待办2.资产管理页面-故障处理
			 * 首页待办: 已传入事件数据
			 * 资产管理页面:传入资产id,自行查询事件数据
			 */
			if(thisPage.eventid)  {
				this.eventid = thisPage.eventid;
				this.eventType= thisPage.type;
				this.eventDesc = thisPage.desc;
				this.eventDepart = thisPage.depart ? thisPage.depart : '';
				this.eventWorkshop = thisPage.workshop ? thisPage.workshop : '';
				this.eventRecorder = thisPage.recorder;
				this.eventRecordDate = thisPage.recorddate.split('T')[0];
				this.eventAssistant = thisPage.assistantname;
				this.passOnDate = thisPage.passondate;
				this.eventAssistant1 = thisPage.assistant1name;
				this.passOnDate1 = thisPage.passondate1;
			} else {
				this.initEventData();
			}
		},
		initEventData: function() {
			var self = this;
			var url = config.requestBaseUrl + "getEquipEvent";
			console.log(url)
			mui.ajax(url,{
				data:{
					equipmentid: this.equipmentid
				},
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:3000,//超时时间设置为10秒；
				success:function(data){
					var thisData = data.data;
					if(data.isSuccess) {
						self.eventid = thisData.id;
						self.eventType= thisData.type;
						self.eventDesc = thisData.desc;
						self.eventDepart = thisData.depart;
						self.eventWorkshop = thisData.workshop;
						self.eventRecorder = thisData.recorder;
						self.eventRecordDate = thisData.recorddate.split('T')[0];
						self.eventAssistant = thisData.assistantname;
						self.passOnDate = thisData.passondate ? thisData.passondate.split('T')[0] : '';
						self.eventAssistant1 = thisData.assistant1name;
						self.passOnDate1 = thisData.passondate1 ? thisData.passondate1.split('T')[0] : '';
						console.log("事件id:" + self.eventid);
					}
				},
				error:function(xhr,type,errorThrown){
					mui.toast("出错啦!" + errorThrown);
				}
			});
		},
		getEquipmentBaseData: function() {
			var self = this;
			var url = config.requestBaseUrl + "getEquipmentBaseInfoById";
			mui.ajax(url,{
				data:{
					equipmentid: this.equipmentid
				},
				dataType:'json',//服务器返回json格式数据
				type:'get',//HTTP请求类型
				timeout:3000,//超时时间设置为10秒；
				success:function(data){
					var thisData = data.data;
					if(data.isSuccess) {
						self.tmbh = thisData.tmbh;
						self.zcbh = thisData.zcbh;
						self.zybbh = thisData.zybbh;
						self.type = thisData.type;
						self.name = thisData.name;
						self.vendor = thisData.vendor;
						self.model = thisData.model;
						self.depart = thisData.depart;
						self.workshop = thisData.workshop;
						self.user = thisData.user;
						self.contact = thisData.contact;
						self.location = thisData.location;
						self.note = thisData.note;
						self.recorder = thisData.recorder;
						self.putindate = thisData.putindate;
						self.state = thisData.state;
					}
				},
				error:function(xhr,type,errorThrown){
					console.log("失败")
				}
			});
		},
		initLayout:function() {
			mui('.mui-scroll-wrapper').scroll({
				scrollY: true, //是否竖向滚动
				scrollX: false, //是否横向滚动
				startX: 0, //初始化时滚动至x
				startY: 0, //初始化时滚动至y
				indicators: true, //是否显示滚动条
				deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
				bounce: true //是否启用回弹
			})
		},
		showInfoDetail: function(boo) {
			this.showEquipmentDetail = boo;
		},
		closeEvent: function() {
			var data = {};
			var self = this;
			if(this.solution) {
				data['solution'] = this.solution;
			}
			var errors = validate(data, this.constraints);
			
			if(errors) {
				if(errors.solution) {
					this.solutionError = errors.solution;
				}
			} else {
				mui.confirm('确定关闭这条事件信息?','确认',['取消','确认'],function (e) {
					if(Number(e.index) == 1) {
						self.submitData();
					}
				},'div');
			}
		},
		submitData: function() {
			var sef = this;
			var url = config.requestBaseUrl + "closeEvent";
			console.log(this.eventid)
			mui.ajax(url,{
				data:{
					eventid: this.eventid,
					solution: this.solution
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:3000,//超时时间设置为10秒；
				success:function(data){
					mui.toast(data.msg);
					if(data.isSuccess) {
						var indexPage = plus.webview.getLaunchWebview();
						mui.fire(indexPage,'refresh',{});
						
						var thisPage = plus.webview.currentWebview();
						thisPage.close();
					}
				},
				error:function(xhr,type,errorThrown){
					mui.toast("出错啦!" + errorThrown);
				}
			});
		}
	}
})